home *** CD-ROM | disk | FTP | other *** search
/ Delphi Informant Complete 1995 - 2000 / Delphi Informant Complete 1995 to 2000.iso / Delphi Informant Magazine Complete Works SOURCE CODE 1995.rar / 1995 / JUN / GE9506 / texcept.pas < prev    next >
Pascal/Delphi Source File  |  1995-05-04  |  1KB  |  52 lines

  1. unit Texcept;
  2.  
  3. { generic exception handler component }
  4.  
  5. interface
  6.  
  7. uses
  8.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  9.   Forms, Dialogs;
  10.  
  11. type
  12.   TExceptionHandler = class(TComponent)
  13.   private
  14.     { Private declarations }
  15.     FActive : Boolean;
  16.   protected
  17.     { Protected declarations }
  18.   public
  19.     { Public declarations }
  20.     procedure OnDo(E: Exception); virtual;
  21.   published
  22.     { Published declarations }
  23.     property Active : Boolean read FActive write FActive;
  24.   end;
  25.  
  26. procedure Register;
  27.  
  28. implementation
  29.  
  30. procedure TExceptionHandler.OnDo(E: Exception);
  31. begin
  32.    { Integer math exceptions }
  33.    if E is EDivByZero then ShowMessage('EDivByZero')
  34.    else if E is ERangeError then ShowMessage('ERangeError')
  35.    else if E is EIntOverFlow then ShowMessage('EIntOverFlow')
  36.    { floating point math exceptions }
  37.    else if E is EInvalidOp then ShowMessage('EInvalidOp')
  38.    else if E is EZeroDivide then ShowMessage('EZeroDivide')
  39.    else if E is EOverflow then ShowMessage('EOverflow')
  40.    else if E is EUnderflow then ShowMessage('EUnderflow')
  41.    else
  42.      ShowMessage('Unhandled Exception.');
  43. end;
  44.  
  45. procedure Register;
  46. begin
  47.   RegisterComponents('WayOfDelphi', [TExceptionHandler]);
  48. end;
  49.  
  50. end.
  51.  
  52.